#
# @lc app=leetcode.cn id=429 lang=python3
#
# [429] N 叉树的层序遍历
#
import collections
from typing import List


class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children
# @lc code=start
"""
# Definition for a Node.

"""

class Solution:
    def levelOrder(self, root: 'Node') -> List[List[int]]:
        if root is None:
            return []
        queue = collections.deque()
        queue.append(root)
        ans = []
        while queue:
            size = len(queue)
            ans.append([])
            while size > 0:
                size -= 1
                node = queue.popleft()
                ans[-1].append(node.val)
                for child in node.children:
                    if child:
                        queue.append(child)
        return ans
# @lc code=end

